<!-- 低代码 主页面：用于区分页面类型 -->

<template>
	<BillList v-if="state.LowcodePage?.c_template === '1'" :lowcode-page="state.LowcodePage" :detailMdCode="state.detailMdCode || ''" :mdInfo="state.mdInfo" />
	<Maintain v-if="state.LowcodePage?.c_template === '2'" :lowcode-page="state.LowcodePage"
		:detailMdCode="state.detailMdCode || ''" :mdInfo="state.mdInfo" />
	<CustomQuery v-if="state.LowcodePage?.c_template === '6'" :lowcode-page="state.LowcodePage" :detailMdCode="state.detailMdCode || ''" :mdInfo="state.mdInfo" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { onLoad } from "@dcloudio/uni-app";
import { initRdsDict } from '@/hooks/init';
import useService from '@/hooks/useService';

import { LOWCODEUNIQUEKEY } from './constant';
import type { LowCodeListPageState, LowcodeMdInfo } from './interface';
import BillList from "./billList/index.vue";
import Maintain from "./maintain/index.vue";
import CustomQuery from "./customQuery/index.vue";

const props = defineProps<{ moduleInfo : string }>();

const state = ref<LowCodeListPageState>({ mdCode: "", detailMdCode: "" });
const service = useService({ prefix: "mainApi" });

const fetchListPage = async () => {
	const mdVal = state.value.mdCode || "";
	uni.showLoading({ title: "查询中...", mask: true });
	const fetchRes = await service.request<string, LowCodeListPageState>(LOWCODEUNIQUEKEY, "FindMobileRuntimeMianPage", mdVal, "", "", { ModuleCode: mdVal });
	uni.hideLoading();

	if (fetchRes !== undefined) {
		state.value = { ...state.value, ...fetchRes as LowCodeListPageState };
	}
};

onLoad(async (option) => {
	const mdInfoStr = decodeURIComponent(option?.moduleInfo);
	const mdInfo : LowcodeMdInfo = JSON.parse(mdInfoStr || "");
	// console.log("mdInfo === >>> ", mdInfo);
	const initParmas = JSON.parse(mdInfo?.c_ini_param || "");
	state.value.detailMdCode = initParmas?.DetailMobilePageGuid || "";
	state.value.mdInfo = mdInfo;
	state.value.mdCode = ((mdInfo?.c_mdcode || "") + "")?.startsWith("mobile_") ? mdInfo?.c_mdcode?.slice?.(7) : "";
	await initRdsDict();
	fetchListPage();
});
</script>